package HttpPages;

import java.util.logging.Level;

import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;

import Database.Database;
import Logger.AppLogger;
import Objects.UserProfile;


@Path("/unregister")
public class Unregister
{

	//-----------------------------------http methods--------------------------------

	//TODO check this method!!! I didn't check it.
	// This method is called if TEXT_PLAIN is request
	@POST
	@Consumes(MediaType.TEXT_PLAIN)
	public String registerationRequest(@FormParam("android_id") String android_id)
	{
		AppLogger.setLevel(Level.INFO);
		AppLogger.write(Level.INFO, "unregister Request was recieved!");

		//removing the userProfile to the database
		UserProfile newUser = Database.getInstance().removeUserProfile(android_id);
		
		if(newUser == null)
		{
			AppLogger.write(Level.WARNING, "unregister was requested by someone who isn't registered");
			return "you are not registered";
		}

		//TODO  -  need to create Response codes file and handle everything!!! 
		return "Unregister message status: Delivered";
	}

}
